package com.fengxing.ams.pub.util;

public class PasswdUtil {

	public static String decrypt(String strSrc) {
		int nSrcLen;
		int nKeyLen;
		int nKeyPos;
		int nOffset;
		String strDest = "";
		int nSrcPos;
		int nSrcAsc;
		int nTmpSrcAsc;
		char[] sTmp = new char[255];
		nSrcLen = strSrc.length();
		if (((nSrcLen < 4) || (nSrcLen % 2 == 1)))
			return ""; // 对于解密时长度小于4或者长度为奇数的直接返回空字符串
		String strKey = "NM Mobile";
		nKeyLen = strKey.length();
		nKeyPos = -1;
		nOffset = Integer.parseInt(strSrc.substring(0, 2), 16);
		nSrcPos = 2;
		do {
			nSrcAsc = Integer.parseInt(strSrc.substring(nSrcPos, 2 + nSrcPos),
					16);
			if (nKeyPos < nKeyLen)
				nKeyPos++;
			else
				nKeyPos = 0;
			nTmpSrcAsc = nSrcAsc ^ strKey.toCharArray()[nKeyPos];
			if (nTmpSrcAsc <= nOffset)
				nTmpSrcAsc = 255 + nTmpSrcAsc - nOffset;
			else
				nTmpSrcAsc = nTmpSrcAsc - nOffset;
			sTmp = (nTmpSrcAsc + "").toCharArray();
			strDest = strDest + (char) Integer.parseInt(new String(sTmp));
			nOffset = nSrcAsc;
			nSrcPos = nSrcPos + 2;
		} while (nSrcPos < nSrcLen);
		return strDest;

	}

}
